# PyMSQL创建数据库连接
from pymysql import Connection

conn = None
try:
    # 创建数据库连接
    conn = Connection(
        host='localhost',  # 主机地址
        port=3306,  # 端口
        user='root',  # 用户名
        password='root'  # 密码
    )
    print(type(conn))
    print(conn.get_host_info())
    print(conn.get_server_info())
except Exception as e:
    print("发生异常：", e)
finally:
    if conn:
        # 关闭连接
        conn.close()
